#!/usr/bin/perl
# $Id: changesplash.pl 3 2006-09-24 08:08:44Z cmauch $
# Author: Charles Mauch (cmauch@gmail.com)
# Description: Randomized Gnome Splash Screen Changer
# Legal: (c) 2006 Charles Mauch, released under the terms of the GPLv2 (or later)

use strict;
use warnings;

my $base_dir = "/home/cmauch/.backgrounds/splashes/";

my @images;
my $sum_images = 0;
my $no_images = 0;
my $ret_code = 0;
  
opendir(DIR, $base_dir); 
@images = readdir(DIR);
closedir(DIR);
  
foreach(@images) { # find and delete . or .. from array
    if ($_ eq ('.' or '..')) {
        splice(@images,$sum_images,1);
        $sum_images--;
    }
    $sum_images++;
}
  
$no_images = int(rand($sum_images)+1);
exec("gconftool-2 --set /apps/gnome-session/options/splash_image $base_dir$images[$no_images] --type string"); 
